# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Simone Sclavi 'Ito' <darkhado@gmail.com>

pkgname=libjpeg-turbo
pkgver=2.0.0
pkgrel=1
pkgdesc='JPEG image codec with accelerated baseline compression and decompression'
url='https://libjpeg-turbo.org/'
arch=('x86_64')
license=('custom')
makedepends=('cmake' 'nasm' 'jdk8-openjdk')
validpgpkeys=('7D6293CC6378786E1B5C496885C7044E033FDE16')
source=("https://downloads.sourceforge.net/project/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('778876105d0d316203c928fd2a0374c8c01f755d0a00b12a1c8934aeccff8868'
            'SKIP')

provides=('libjpeg=8.2.2')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	sed 's/Szathmáry/Szathmary/g' -i java/org/libjpegturbo/turbojpeg/*.java
}

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	cmake \
		-DWITH_JAVA=1 \
		-DWITH_JPEG8=1 \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		.

	make
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make test
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make \
		DESTDIR="${pkgdir}" \
		docdir="/usr/share/doc/${pkgname}" \
		exampledir="/usr/share/doc/${pkgname}" \
		install

	install -d "${pkgdir}/usr/share/licenses/${pkgname}"
	ln -s ../../doc/libjpeg-turbo/LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}"
	install -m 644 jpegint.h "${pkgdir}/usr/include" # required by other software
}
